package com.aaa.sb.controller;

import com.aaa.sb.service.DeptService;
import com.aaa.sb.util.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * className:DeptController
 * discription:
 * author:zz
 * createTime:2018-11-21 11:32
 */
@RestController
@RequestMapping("/dept")
public class DeptController {

    //依赖注入
    @Autowired
    private DeptService deptService;

    /**
     * 部门列表方法
     * @return
     */
    @RequestMapping("/list")
    public Object list(){
        List<Map> list = deptService.getList();
        return list;
    }

    /**
     * 添加
     * @return
     */
    @RequestMapping("/insertDept")
    public Object add(@RequestParam Map map){
        int i = deptService.insertDept(map);
        Map map1 = new HashMap();
        if (i > 0) {
            map1.put("msg","添加成功！");
        } else {
            map1.put("msg","添加失败！");
        }
        return map1;
    }
    /**
     * 更新
     * @return
     */
    @RequestMapping("/updateDeptMsg")
    public Object updateDeptMsg(@RequestParam Map map){
        int i = deptService.updateDeptMsg(map);
        Map map1 = new HashMap();
        if (i > 0) {
            map1.put("msg","更新成功！");
        } else {
            map1.put("msg","更新失败！");
        }
        return map1;
    }
    /**
     * 删除新闻
     * @return
     */
    @RequestMapping("/deleteOne")
    public Object deleteOne(@RequestParam Map map) {
        int i = deptService.deleteOne(map);
        Map map1 = new HashMap();
        if (i > 0) {
            map1.put("msg","删除成功！");
        } else {
            map1.put("msg","删除失败！");
        }
        return map1;
    }
    /**
     * 通过deptno查dept
     * @return
     */
    @RequestMapping("/selectDeptById")
    public Object selectDeptById(@RequestParam Map paramMap, Model model) {
        List<Map> deptList = deptService.selectDeptById(paramMap);
        return deptList;
    }
}
